package com.renu.jdependencyanalyser.window.action;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.renu.jdependencyanalyser.cons.ProjectCons;
import com.renu.jdependencyanalyser.core.ProjectInfo;
import com.renu.jdependencyanalyser.data.ProjectDataCenter;
import com.renu.jdependencyanalyser.freemarker.DependencyProcessor;
import com.renu.jdependencyanalyser.model.MethodModel;
import com.renu.jdependencyanalyser.utils.MyFileUtil;
import com.renu.jdependencyanalyser.utils.MyProjectUtil;
import com.renu.jdependencyanalyser.visualizer.GraphvizVisualizer;
import com.renu.jdependencyanalyser.utils.ImageDialogUtil;
import org.jetbrains.annotations.NotNull;

import java.io.File;

public class OuterMthdDpndcyPseudoAction extends AnAction {
      GraphvizVisualizer graphvizVisualizer;
    ProjectInfo projectInfo = ProjectDataCenter.projectInfo;



    MethodModel methodModel ;

    public OuterMthdDpndcyPseudoAction(String methodSig) {
        this.methodModel  = projectInfo.getBorderMethodMap().get(methodSig);
        if (methodModel == null){
            return ;
        }
        graphvizVisualizer = new GraphvizVisualizer();

        MyFileUtil.createOutDir(MyProjectUtil.projectBasePath + ProjectCons.OUTER_METHOD_INVOKE_DIR);
        String methosSig = methodModel.getMethodSig().split("\n")[1];
        //void setApplicationClass()-setApplicationClass>
        String methosName = methosSig.split("\\s+")[1];
        String filePath = MyProjectUtil.projectBasePath + ProjectCons.OUTER_METHOD_INVOKE_DIR + File.separator +methosName + ".png";

        graphvizVisualizer.generateGraph(new DependencyProcessor(projectInfo,methodModel),filePath);

        ImageDialogUtil.showImage(filePath,"查看"+methosName+"方法的依赖图");


    }

    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {

    }
}
